<template>
	<div class="comp-new">
		<el-form ref="newForm" :model="newForm" :label-width="150+'px'">
			<el-form-item label="所属机构">
		    	潍坊监管
		  	</el-form-item>
			<el-form-item label="部门名称：" prop="name" :rules="[{ required: true, message: '请输入部门名称', trigger: 'change' }]">
		    	<el-input placeholder="请输入" v-model.trim="newForm.name"></el-input>
		  	</el-form-item>
		  	<el-form-item label="部门描述：" prop="des" :rules="[{ required: true, message: '请输入部门描述', trigger: 'change' }]">
		  		<el-input placeholder="请输入" type="text" v-model.trim="newForm.des"></el-input>
		  	</el-form-item>
		</el-form>
	</div>	
</template>
<script>
import { mapState } from 'vuex'
export default {
	name: 'newRecordAccount',
	props: {
		activeData: {
			type: Object,
			default(){
				return null
			},
		}
	},
	computed: {
		...mapState([
			'scale'
		]),
	},
	watch: {
		activeData () {
			this.initForm()
		}
	},
	data () {
		return {
			newForm: {},
			loading: false
		}
	},
	methods: {
		initForm () {
			if(this.activeData){
				this.newForm = Object.assign({},this.activeData)
			}else{
				this.newForm = {}
				if(this.$refs['newForm']){
					this.$refs['newForm'].resetFields()
				}
			}
		},
		submitAction () {
			this.$refs['newForm'].validate((valid) => {
				return
				if (valid) {
					this.$emit('submitting')
					this.loading = true
					let params = Object.assign({},this.newForm)
					params.enable = params.enable=='1'
					this.$ajax({
						url: '/facility',
						method: params.id ? 'put' : 'post',
						data: params
					}).then( data => {
						this.loading = false
						this.$message({
							type: 'success',
							message: '保存成功',
							center: true
						})
						this.$emit('success',data);
					}, error => {
						this.loading = false
						this.$message.error(error.msg);
					})
				} else {
					return false;
				}
			});
		},
		cancelAction () {
			this.$emit('cancel');
		}
		// resetForm () {
		// 	this.newForm = {}
		// 	this.$refs['newForm'].resetFields()
		// }
	},
	created () {
		this.initForm()
	},
}
</script>